////////////////////////////////////////////////////////////////////////////////
//
//  DIGITAS FRANCE / VIVAKI COMMUNICATIONS
//  Copyright 2008-2009 Digitas France
//  All Rights Reserved.
//
//  NOTICE: Digitas permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////


package pro.lepers.portfolio.view.contents.portfolio.misc {
	import flash.utils.Dictionary;
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;

	public dynamic class ProxyClient extends Proxy {
		
		
		public function ProxyClient( loader : Object ) {
			_loader = loader;
			_dHandlers = new Dictionary( );
			defaultHandler = _defaultHandler;
		}

		public function addHandler( name : String, callBack : Function ) : void {
			_dHandlers[ name ] = callBack;
		}
		
		public var defaultHandler : Function;
		
		public function _defaultHandler( infoObj : Object ) : void {
			
		}
		
		override flash_proxy function callProperty( methodName : *, ... args ) : * {
			if( ! _loader.hasOwnProperty( methodName ) ) return;
	        if( ! ( _loader[ methodName ] is Function ) ) return;
			return _loader[ methodName ].apply( _loader, args );
		}

		override flash_proxy function getProperty(name : *) : * {
	        if( ! _loader.hasOwnProperty( name ) ) {
				if( _dHandlers[ name ] != undefined ) return _dHandlers[ name ];
				return defaultHandler as Object;
			}
			return _loader[name];
		}

		override flash_proxy function setProperty(name : *, value : *) : void {
	        if( ! _loader.hasOwnProperty( name ) ) return;
			_loader[name] = value;
		}

		internal function dispose() : void {
			_loader = null;
		}
		
		
		private var _loader : Object;

		private var _dHandlers : Dictionary;

	}
}
